
<!--搜索框-->
<div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="layadmin-useradmin-formlist">
    <div class="layui-form-item">
        <div class="layui-inline">
            <input type="text" name="title" placeholder="标题" autocomplete="off" class="layui-input" value="">
        </div>
        <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-admin layui-btn-primary" lay-submit lay-filter="LAY-user-back-search">
                <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i> 搜索
            </button>
        </div>
    </div>
</div>

<div class="layui-card-body">
    <!--表格-->
    <table id="demo" lay-filter="test"></table>
    <!--行功能-->
    <script type="text/html" id="row_operation">
        <a class="layui-btn layui-btn-normal-outline layui-btn-xs" lay-event="detail">查看</a>
    </script>
</div>
<script>
    layui.use('table',function () {
        var table = layui.table,form = layui.form;

        //初始化表格
        var tableIns = table.render({
            elem: '#demo'
            ,url: '/admin/notice_log/index/' //数据接口
            ,page: true //开启分页
            ,limit: 15
            ,cols: [[ //表头
                 {field: 'title', title: '标题',align:'center'}
                ,{field: 'create_time', title: '创建时间',align:'center'}
                ,{field: 'read_status', title: '状态',align:'center'}
                ,{fixed: 'right', title:'操作', toolbar: '#row_operation', width:200,align:'center'}
            ]]
        });

        //监听搜索
        form.render(null, 'layadmin-useradmin-formlist');
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            tableIns.reload({
                where: field
                ,page: {
                        curr: 1 //重新从第 1 页开始
                }
            });
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(obj);
            if(obj.event === 'detail'){
                layer.open({
                    type: 2
                    ,title: '详情'
                    ,content: "{:url('notice_log/detail')}?id="+data.id
                    ,shadeClose: true
                    ,shade: 0.4
                    ,area: ['800px', '800px']
                });

            }
        });
    });

    //头部功能条
    $('.top_toolbar').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
    //事件对象
    var active = {
        add: function(){
            layer.open({
                type: 2,
                title: '添加',
                shadeClose: true,
                shade: 0.4,
                area: ['800px', '600px'],
                content: '/admin/notice/create', //iframe的url
                btn: ['确认', '取消'],
                yes:function(index, layero){
                    //按钮【按钮一】的回调
                    //点击确认触发 iframe 内容中的按钮提交
                    var submit = layero.find('iframe').contents().find("#form-submit");
                    submit.click();
                },
                btn2:function(index,layero){
                    //按钮【按钮二】的回调
                    layer.close(index);
                }
            });
        }
    }
</script>